package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService{
    @Autowired
    private DepartmentMapper departmentMapper;

    public int deleteByPrimaryKey(Long id) {
        return departmentMapper.deleteByPrimaryKey(id);
    }

    public int insert(Department record) {
        return departmentMapper.insert(record);
    }

    public Department selectByPrimaryKey(Long id) {
        return departmentMapper.selectByPrimaryKey(id);
    }

    public List<Department> selectAll() {
        return departmentMapper.selectAll();
    }

    public int updateByPrimaryKey(Department record) {
        return departmentMapper.updateByPrimaryKey(record);
    }
   

    //分页
    public PageResult query(QueryObject qo){
        //查总数
        int total = departmentMapper.queryForCount(qo);
         if(total==0){
             return new PageResult();
         }
         //查每页数据
        List<Department> rows = departmentMapper.queryForList(qo);
        return new PageResult(rows,total);
    }
     //改变状态
    public void changeState(Long id) {
        departmentMapper.changeState(id) ;
    }


}
